home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15614 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: What is wrong with this loop?
  5. Date: 19 Apr 1996 18:36:20 -0700
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4l9f2kINN8j7@keats.ugrad.cs.ubc.ca>
  8. References: <4l86la$1t9@uwm.edu> <4l8apa$kv8@spanky.pls.ov.com>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <4l8apa$kv8@spanky.pls.ov.com>,
  12. Fletcher.Glenn@ov.com <glenn@ov.com> wrote:
  13.  
  14. >My bet is that you have forgotten that the '\n' in your input is
  15. >also a character.  Try changing your while statement from:
  16.  
  17. ...because the %c conversion specifier is a special case which suppresses the
  18. skipping of whitespace.
  19.  
  20. >   while (cd != 'm' || cd ! 'f' || cd != 'o')
  21. >
  22. >to:  while(cd != 'm' || cd != 'f' || cd != 'o' || cd != '\n')
  23.  
  24. You didn't fix his logic problem:
  25.  
  26.     while(cd != 'm' && cd != 'f' ... )
  27.  
  28. Since cd cannot simultaneously be 'm' and 'f', either (cd != 'm') or (cd !=
  29. 'f') must always be true. Hence with an or, you get an infinite loop.
  30.  
  31. Also, now the code accepts '\n' as a valid character which must be tested for
  32. subsequently.
  33.